﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Rison.BusinessFacade.Common
{
    public enum SqlOperator
    {
        Equal,//等于
        NotEqual,//不等于
        LargerThan,//大于
        LessThan,//小于
        LargerEqual,//大于等于
        LessEqual,//小于等于
        Like,//Like
        In,//In
        NotIn,//Not In 
        Null,//Is Null
        NotNull,//Is Not Null
        Exists,
        NotExists
    }

    public enum NextConnectSign
    {
        And,//And
        OR,//OR
        And_LeftParen,//And (
        RightParen,//)
        RightParen_And     //) And
    }

    public sealed class Condition
    {
        private string _fieldName = string.Empty;
        private string _value = string.Empty;
        private bool _needQuotes = true;
        private SqlOperator _operator = SqlOperator.Equal;
        private NextConnectSign _connectSign = NextConnectSign.And;

        public string FieldName
        {
            get { return _fieldName; }
        }
        public string Value
        {
            get { return _value; }
        }
        public bool NeedQuotes
        {
            get { return _needQuotes; }
        }
        public SqlOperator Operator
        {
            get { return _operator; }
            set { _operator = value; }
        }
        public NextConnectSign ConnectSign
        {
            get { return _connectSign; }
            set { _connectSign = value; }
        }

        public Condition(string fieldname, string value)
        {
            _fieldName = fieldname;
            _value = value;
        }

        public Condition(string fieldname, SqlOperator ope, string value)
        {
            _fieldName = fieldname;
            _operator = ope;
            _value = value;

            if (ope == SqlOperator.Exists || ope == SqlOperator.NotExists) _needQuotes = false;
        }

        public Condition(string fieldname, SqlOperator ope, string value, bool needQuotes)
        {
            _fieldName = fieldname;
            _operator = ope;
            _value = value;
            _needQuotes = needQuotes;
        }

        public Condition(string fieldname, SqlOperator ope, string value, NextConnectSign connectSign)
        {
            _fieldName = fieldname;
            _operator = ope;
            _value = value;
            _connectSign = connectSign;

            if (ope == SqlOperator.Exists || ope == SqlOperator.NotExists) _needQuotes = false;
        }

        public Condition(string fieldname, SqlOperator ope, string value, bool needQuotes, NextConnectSign connectSign)
        {
            _fieldName = fieldname;
            _operator = ope;
            _value = value;
            _needQuotes = needQuotes;
            _connectSign = connectSign;
        }
    }
}
